<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 区别在于有重复数字，最后推入时去重即可 */
            var permuteUnique = function (nums) {
                let res = []
                let use = []
                let map = new Map()
                function backTacking(path, use) {
                    if (path.length == nums.length) {
                        let str = path.join(".")
                        if (map.has(str)) return
                        map.set(str, 1)
                        return res.push([...path])
                    }
                    for (let i = 0; i < nums.length; i++) {
                        if (use[i]) continue
                        use[i] = true
                        path.push(nums[i])
                        backTacking(path, use)
                        path.pop()
                        use[i] = false
                    }
                }
                backTacking([], use)
                return res
            }
        </script>
    </body>
</html>
